package com.nbgroup.controller;


import cn.hutool.core.bean.BeanUtil;
import com.nbgroup.pojo.Business;
import com.nbgroup.pojo.common.PageBean;
import com.nbgroup.pojo.common.Result;
import com.nbgroup.pojo.dto.AssignmentOrGainBusiDTO;
import com.nbgroup.pojo.dto.BusinessDTO;
import com.nbgroup.pojo.dto.BusinessPageQueryDTO;
import com.nbgroup.service.IBusinessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 商机表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-10-27
 */
@Api(tags = "商机接口")
@RestController
@RequestMapping("/business")
public class BusiController {

    @Autowired
    private IBusinessService businessService;

    /**
     * 商机分页查询
     */
    @GetMapping("/list")
    @ApiOperation("分页查询")
    public PageBean pageQuery(BusinessPageQueryDTO dto){
        PageBean page = businessService.PageQuery(dto);
        return page;
    }

    /**
     * 新增商机
     */
    @PostMapping
    @ApiOperation("新增商机")
    public Result add(@RequestBody BusinessDTO dto){
        Business business = BeanUtil.copyProperties(dto, Business.class);
        businessService.save(business);
        return Result.success();
    }

    /**
     * 查看商机
     */
    @GetMapping("/{id}")
    public Result queryById(@PathVariable Long id){
        Business business = businessService.getById(id);
        return Result.success(business);
    }

    /**
     * 分配商机
     */
    @PutMapping("/assignment")
    public Result assignBusiness(@RequestBody AssignmentOrGainBusiDTO dto){
        businessService.gainOrAssignBusi(dto);
        return Result.success();
    }

    /**
     * 捞取商机
     */
    @PutMapping("/gain")
    public Result gainBusiness(@RequestBody AssignmentOrGainBusiDTO dto){
        businessService.gainOrAssignBusi(dto);
        return Result.success();
    }

    /**
     * 公海池查询
     */
    @GetMapping("/pool")
    @ApiOperation("公海池分页查询")
    public PageBean pageQueryPool(BusinessPageQueryDTO dto){
        PageBean page = businessService.PageQuery(dto);
        return page;
    }
}
